import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:interview/components/app/app_ripple_button.dart';
import 'package:interview/components/tag.dart';
import 'package:interview/controller/navigation_controller.dart';
import 'package:interview/theme/app_colors.dart';

class OptItem extends StatelessWidget {
  final AppColors theme;
  final String id;
  final List<String> ids;
  final String stem;
  final String? subjectName;
  final String? creatorName;
  final String? createdAt;
  final String? creatorAvatar;
  final int difficulty;
  final int? questionType;
  const OptItem({
    super.key, 
    required this.id,
    required this.ids,
    required this.theme, 
    required this.stem, 
    this.subjectName = "前端开发", 
    this.creatorName = "User", 
    this.createdAt, 
    this.creatorAvatar,
    required this.difficulty,
    this.questionType,
  });

  // 根据 questionType 获取题型的文本
  String getQuestionTypeText(int type) {
    switch (type) {
      case 1:
        return "单选题";
      case 2:
        return "多选题";
      case 3:
        return "判断题";
      case 5:
        return "简答题";
      case 6:
        return "代码题";
      case 7:
        return "实操题";
      default:
        return "未知题型";
    }
  }

 

  @override
  Widget build(BuildContext context) {
  final navigation = Get.find<NavigationController>();
  void _onTap () {
    /// 跳转的逻辑 只有首页跳转时才需要传递 typeId  目标是同步 首页和详情页的 views  其他逻辑跳转时 传值为0  会忽略同步views逻辑
    navigation.pushWithAuth(
      '/questionpage' , 
      parameters: {
        "id" : id , 
        "ids":ids , 
        "typeId":0,
        "views":0
      }
    );
  }
    return AppRippleButton(
      onTap: _onTap,
      highlightColor: theme.contrastMix1!.withOpacity(0.4),
      splashColor:theme.contrastMix1!.withOpacity(0.4) ,
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(4),
          color: theme.subjectMix1
        ),
        child: Padding(
          padding: const EdgeInsets.all(12.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Wrap(
                spacing: 8.0,
                runSpacing: 4.0,
                children: [
                  Text( subjectName!, style: TextStyle(fontSize: 10, color: theme.contrastMix3 , fontWeight: FontWeight.w500)),
                  Text( stem, style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: theme.contrastPure)),
                  Tag(difficulty: difficulty),
                  Tag(text:getQuestionTypeText(questionType!))
                ],
              ),
              Container(
                padding: EdgeInsets.only(top: 12, bottom: 12),
                width: double.infinity,
                child:  Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(creatorName! ,style: TextStyle(fontSize: 10, color: theme.contrastPure , fontWeight: FontWeight.bold) ),
                    CircleAvatar(
                      backgroundImage: NetworkImage(creatorAvatar!),
                      radius: 16,
                    ),
                  ],
                ),
              ),
              SizedBox(
                width: double.infinity,
                child: Text(
                  createdAt! , 
                  style: TextStyle(fontSize: 10 , fontWeight: FontWeight.bold , color: theme.contrastMix3), 
                  textAlign: TextAlign.end
                ),
              )
            ],
          ),
        ),
      )
    );
  }
}